// --------------------------------------------------------------------------------------------------------------------
// <copyright file="Edge.cs" company="Microsoft Corporation">
// The MIT License (MIT)
// 
// Copyright (c) 2014, Microsoft Corporation
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy
//  of this software and associated documentation files (the "Software"), to deal
//  in the Software without restriction, including without limitation the rights
//  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//  copies of the Software, and to permit persons to whom the Software is
//  furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in
//  all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//  THE SOFTWARE.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
namespace Microsoft.Robotics.Numerics.GraphOptimization
{
    /// <summary>
    /// Base edge class
    /// </summary>
    /// <typeparam name="T">Type of nodes the edge connects</typeparam>
    public abstract class Edge<T>
    {
        /// <summary>
        /// Initializes a new instance of the Edge class
        /// </summary>
        /// <param name="i">Index of the $Ith$ node in the graph</param>
        /// <param name="j">Index of the $Jth$ node in the graph</param>
        /// <param name="measurement">Measurement between the poses</param>
        /// <param name="dimensions">Number of dimensions of the parameter space</param>
        public Edge(int i, int j, T measurement, int dimensions)
        {
            this.IndexI = i;
            this.IndexJ = j;
            this.Measurement = measurement;
            this.Dimensions = dimensions;
        }

        /// <summary>
        /// Pointer to function that computes the error 
        /// </summary>
        /// <param name="state1">State one</param>
        /// <param name="state2">State two</param>
        /// <returns>Minimal representation of the error</returns>
        public delegate T ErrorFunction(T state1, T state2);

        /// <summary>
        /// Gets the number of dimensions of the parameter space
        /// </summary>
        public int Dimensions { get; private set; }

        /// <summary>
        /// Gets the minimal representation for the edge measurement between two nodes
        /// </summary>
        public T Measurement { get; private set; }

        /// <summary>
        /// Gets the index of the $Ith$ node in the graph
        /// </summary>
        public int IndexI { get; private set; }

        /// <summary>
        /// Gets the index of the $Jth$ node in the graph
        /// </summary>
        public int IndexJ { get; private set; }

        /// <summary>
        /// Gets the $xth$ basis vector of the parameter space
        /// </summary>
        /// <param name="x">x basis vector</param>
        /// <param name="scale">value which to scale the vector</param>
        /// <returns>$xth$ basis vector</returns>
        public abstract double[] ScaledBasisVector(int x, double scale);
    }
}
